package J250405;

import java.io.*;
import java.nio.charset.StandardCharsets;

public class IO1 {
    public static void main(String[] args) throws IOException {
        try (FileInputStream inputStream = new FileInputStream("./testDir/dir1/dir2/renameTo.txt")) {
            while (true) {
                byte[] bytes = new byte[1024];
                int n = inputStream.read(bytes);
                if (n == -1) {
                    break;
                }
                for (int i = 0; i < n; i++) {
                    System.out.printf("0x%X ",bytes[i]);
                }
            }
        }

        try (OutputStream outputStream = new FileOutputStream("./testDir/dir1/dir2/renameTo.txt",true)) {
            byte[] bytes = "你好世界".getBytes(StandardCharsets.UTF_8);
            outputStream.write(bytes);
        }
    }
}
